package com.lg.mengbase.testlistview.adapter;

import android.content.Context;

import com.lg.baselibrary.adapter.BaseAbsListViewAdapter;
import com.lg.baselibrary.adapter.BaseAbsListViewHolder;
import com.lg.mengbase.R;
import com.lg.mengbase.entity.ItemMsg;

/**
 * Created by LiGang on 2017/5/28.
 */

public class MessageListAdapter extends BaseAbsListViewAdapter<ItemMsg>{
    private static final int LAYOUT_RECEIVER = R.layout.item_session_text_left;
    private static final int LAYOUT_SEND = R.layout.item_session_text_right;
    public MessageListAdapter(Context context) {
        super(context);
    }

    @Override
    public void convert(BaseAbsListViewHolder viewHolder, ItemMsg item, int position) {
        switch (viewHolder.getLayoutId()){
            case LAYOUT_RECEIVER:
                viewHolder.setText(R.id.tv_msg_receive,item.content);
                break;
            case LAYOUT_SEND:
                viewHolder.setText(R.id.tv_msg_send,item.content);
                break;
        }
    }

    @Override
    protected int getItemViewLayout(int position) {
        ItemMsg itemMsg = getItem(position);
        if(itemMsg.direction == ItemMsg.MessageDirection.RECEIVE){
            return LAYOUT_RECEIVER;
        }
        if(itemMsg.direction == ItemMsg.MessageDirection.SEND){
            return LAYOUT_SEND;
        }
        return 0;
    }
}
